//make copy a large file more than 2GB on x86 archive available
#define _FILE_OFFSET_BITS 64
#define _LAGREFILE64_SOURCE
#include<stdio.h>
#include<sys/types.h>
#include<unistd.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<stdlib.h>
int main(int argc, char *argv[])
{
    int fileo,fileo1,filew,filer,len,mode1;
    long long *buf;
    struct stat mod;
    lstat(argv[1],&mod);
    mode1=mod.st_mode;          //获取源文件权限
    fileo=open(argv[1],O_RDONLY|O_CREAT,00644);
    if(fileo==-1)
    {
        perror("cannot open/creat file");
        exit(0);
    }
    fileo1=open(argv[2],O_RDWR|O_CREAT,mode1);
    if(fileo1==-1)
    {
        perror("cannot open/creat file");
        exit(0);
    }
    struct stat buffer;
    fstat(fileo,&buffer);
    len=buffer.st_size;
    buf=(malloc(len));
    //sleep(2);
    //printf("the file's length is %d",len);
    /*filer=read(fileo,buf,len);
    if(filer==0)
        perror("end of file");
    else if(filer==-1)
        perror("cannot read");
    else
        printf("read success");*/
    filew=write(fileo1,buf,len);
    if(filew==-1)
    {
        perror("cannot write");
        exit(0);
    }
    else
        printf("\t copy success\n");
}
